<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('goodsorder');

require_once "function.php";
//初始化参数

$action  = isset($action)  ? $action  : '';
$repairid = isset($repairid) ? $repairid : ''; //任务类型
$manageid = isset($manageid) ? $manageid : ''; //执行人员
$beginTime = isset($beginTime) ? $beginTime : '';
$endTime = isset($endTime) ? $endTime : '';


?>

<div class="toolbarTab">
  <div class="tool2 row">
    <div class="col-md-1">
      <div  class="tool1"><span class="btn btn-success" onclick="getFangAll()"><span class="icon-list-alt icon-white"></span> 全部奖励</span></div>
    </div>
      
  </div>
  <div class="row tool2">
    <div class="col-md-4">
      <div class="s-label"><span class="glyphicon glyphicon-wrench"></span> 任务类型：</div>
      <select class="form-control w300" name="repairid" id="repairid" onchange="getFeeSearch()">
        <option value="-1">所有方式</option>
        <?php

					$dosql->Execute("SELECT * FROM `#@__cascadedata` WHERE `datagroup`='renwu' order by orderid ASC",4);

					while($row = $dosql->GetArray(4))

					{

						if($repairid == $row['datavalue'])

							$selected = 'selected="selected"';

						else

							$selected = '';

						echo '<option value="'.$row['datavalue'].'" '.$selected.'>'.$row['dataname'].'</option>';

					}

					?>
      </select>
    </div>
    <div class="col-md-4">
          <div class="s-label"><span class="	glyphicon glyphicon-ok-sign"></span> 执行人员：</div>
          <select  class="form-control w200" name="manageid" id="manageid" onchange="getFeeSearch()">
            <option value="-1">所有</option>
            <?php
                        $dosql->Execute("SELECT * FROM  `#@__user`  WHERE   level='3'  order by id desc",10);
                        while($row = $dosql->GetArray(10))
                        {
                            if($manageid == $row['id'])
                                $selected = 'selected="selected"';
                            else
                                $selected = '';
                            echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['school']."-".$row['truename'].'</option>';
                        }
                        $dosql->Execute("SELECT * FROM  `#@__user`  WHERE   level='5'  order by id desc",10);
                        while($row = $dosql->GetArray(10))
                        {
                            if($manageid == $row['id'])
                                $selected = 'selected="selected"';
                            else
                                $selected = '';
                             echo '<option value="'.$row['id'].'" '.$selected.'>'.$row['school']."-".$row['truename'].'</option>';
                        }
                        ?>
          </select>
        </div>
    <div class="col-md-4">
      <div class="input-group" style=" float:left;width: 240px; margin-left: -5px;">
        <input class="form-control date-picker" id="dateTimeRange" value="<?php echo $beginTime?>至<?php echo $endTime?>" type="text">
        <span class="input-group-addon"> <i class="glyphicon glyphicon-calendar bigger-110"></i> </span>
        <input name="beginTime" id="beginTime" value="<?php echo $beginTime?>" type="hidden">
        <input name="endTime" id="endTime" value="<?php echo $endTime?>"  type="hidden">
      </div>
      <a href="javascript:;" onclick="begin_end_time_clear();"  style="float:left; margin-left:20px; height:34px; line-height:34px;">清除</a> </div>
      
    
  </div>
  
</div>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="ajaxlist" class="dataTable table table-striped table-bordered">
  <tr height="50" align="left" class="head">
    <td width="3%">ID</td>
    <td width="10%">执行人</td>
    <td width="10%">任务类型</td>
    <td width="10%">单位</td>
    <td width="15%">任务摘要</td>
    <td width="10%">操作时间</td>
    <td width="10%">增加/减少</td>
    <td width="10%">事由</td>
    <td width="8%">任务奖励</td>
  </tr>
  <?php
	//检查全局分页数
	if(empty($cfg_pagenum))  $cfg_pagenum = 50;
	//设置sql
$sql_order = "SELECT f.* ,o.school as school,o.repairid as  repairid,o.content as content ,u.truename as truename  FROM `#@__fee_log` as f
		left join `#@__order` as o on o.id=f.orderid  
		left join `#@__user`   as u on u.id=f.manageid
		WHERE   f.jindu>'2'   ";
	if(!empty($manageid)) $sql_order .= " AND f.manageid='$manageid'  ";
	if(!empty($repairid))  $sql_order .= " AND o.repairid='$repairid'  ";
	if(!empty($beginTime)  && !empty($endTime) ) {
			$starttime = strtotime($beginTime." 00:00");

			$endtime = strtotime($endTime)+86400; //加一天
			$sql_order .= " AND f.op_time > ". $starttime ." AND f.op_time < ".$endtime;
	}


	//获取所有的 记录合计
	$all_fee="";
	$dosql->Execute($sql_order,7);
	while($order=$dosql->GetArray(7)){
		if($order['op']=='add'){
			$all_fee+=$order['fee'];
		}elseif($order['op']=='move'){
			$all_fee-=$order['fee'];
		}
	}



	$dopage->GetPage($sql_order);
	while($row = $dosql->GetArray())
	{
		if(intval($row['fee'])>0  ){
			$fee='<span class="label label-danger">'.$row['fee'].'</span>';	
		}else{
			if($row['jindu']>4){
				$fee='<span class="label label-success">免费</span>';	
			}else{
				$fee='';
			}	
		}
		
		$tr_color="";
		if($row['op']=='add'){
			$op_str='<i class=" red glyphicon glyphicon-plus">  增加</i>';
		}elseif($row['op']=='move'){
			$op_str='<i class="green glyphicon glyphicon-minus">  减少</i>';
			$tr_color='class="success"';
		}
	
	?>
  <tr align="left"  <?php echo $tr_color;?>  >
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['truename']; ?></td>
    <td><?php echo getRepairMode($row['repairid']); ?></td>
    <td><?php echo $row['school']; ?></td>
    <td><?php echo $row['content']; ?></td>
    <td><?php echo date("Y-m-d H:i:s",$row['op_time'])?></td>
    <td><?php echo $op_str;?></td>
    <td><?php echo $row['remark'];?></td>
    <td><?php echo $fee;?></td>
  </tr>
  <?php

	}

	?>
    <tr><td colspan="8"></td><td class="red">合计：<b><?php echo $all_fee;?></b></td></tr>
</table>
<?php



//判断无记录样式

if($dosql->GetTotalRow() == 0)
{
	echo '<div class="dataEmpty">暂时没有相关的记录</div>';
}?>
<div class="page"> <?php echo $dopage->AjaxFeePage(); ?> </div>
<?php

		//审核销售

if($cfg_adminlevel == 1)

{



?>
<?php

}

//判断是否启用快捷工具栏

if($cfg_quicktool == 'Y'  && $cfg_adminlevel == 1)

{

?>
<div class="quickToolbar">
  <div class="qiuckWarp">
    <div class="quickArea"><?php echo $dopage->AjaxPageSmall(); ?> </div>
    <div class="quickAreaBg"></div>
  </div>
</div>
<?php

}



?>
<script type="text/javascript">
$(function() {
	$('#dateTimeRange').daterangepicker({
		applyClass : 'btn-sm btn-success',
		cancelClass : 'btn-sm btn-default',
		locale: {
			applyLabel: '确认',
			cancelLabel: '取消',
			fromLabel : '起始时间',
			toLabel : '结束时间',
			customRangeLabel : '自定义',
			firstDay : 1
		},
		ranges : {
			//'最近1小时': [moment().subtract('hours',1), moment()],
			'今日': [moment().startOf('day'), moment()],
			'昨日': [moment().subtract('days', 1).startOf('day'), moment().subtract('days', 1).endOf('day')],
			'最近7日': [moment().subtract('days', 6), moment()],
			'最近30日': [moment().subtract('days', 29), moment()],
			'本月': [moment().startOf("month"),moment().endOf("month")],
			'上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")]
		},
		opens : 'right',	// 日期选择框的弹出位置
		separator : ' 至 ',
		showWeekNumbers : true,		// 是否显示第几周


		//timePicker: true,
		//timePickerIncrement : 10,	// 时间的增量，单位为分钟
		//timePicker12Hour : false,	// 是否使用12小时制来显示时间


		maxDate :<?php echo date("Y-m-d",time())?>,			// 最大时间
		format: 'YYYY-MM-DD'

	}, function(start, end, label) { // 格式化日期显示框
		$('#beginTime').val(start.format('YYYY-MM-DD'));
		$('#endTime').val(end.format('YYYY-MM-DD'));
		getFeeSearch();
		
	})
	.next().on('click', function(){
		$(this).prev().focus();
	});
});

/**
 * 清除时间
 */
function begin_end_time_clear() {
	$('#dateTimeRange').val('');
	$('#beginTime').val('');
	$('#endTime').val('');
}



function delM(id){
		
		var id_name=$("#m_"+id).data("index");
		var del_str="您确定要删除    "+id_name+"   吗, 确认删除?";
	    layer.confirm(del_str, function() {
		   //操作 
		  $.ajax({
			  type: 'POST',
			  url: "op.php",
			  data: {id:id,op:'delM'},
			  dataType: 'JSON',
			  success:function(result){
			  console.log(result);
				if(result.errno==0){
					 console.log(result.msg);
					if(result.msg==="ok"){
						layer.msg('删除成功');
						window.location.reload();
					}else{
						 layer.msg(result.err_msg);
					}
				}
			  }
		  });
        }, function() {
          //取消操作
        });

}


</script>
<style>
.nav-tabs>li.active>a{
	color: #fff !important;
	background-color: #337ab7 !important;
}
</style>
<script>

$('#myTabs a').click(function (e) {
  e.preventDefault()
  $(this).tab('show')
})
</script>